<style>
    .static-info {
        padding: 20px;
        text-align: left;
        padding-top: 30px;
        margin-left: -50px;
    }

    .image_contain{
        background: rgba(12,12,12,0.2);
        padding: 6px;
        text-align: center;
    }

    .static-info i {
        color: #ce472e;
    }

    .static-info span {
        font-size: 16px;
        color: #ac2176;
    }
</style>
<script type="text/javascript">
    $(document).ready(function () {
        $("#reset").click(function () {
            $("select").val('');
            $("input[type='text']").val('');
        });
    });
</script>

<div class="row">
    <div class="col-xs-12">
        <div class="portlet box green">
            <?= edit_form_caption('财务申请') ?>
            <div class="portlet-body">
                <?= form_open('', Array('class' => 'form-horizontal', 'role' => 'form', 'id' => 'form_edit')) ?>
                <div class="form col-md-12">
                    <?= edit_form_dropdown('finance_id', $allFinance, set_value('finance_id', $obj->finance_id), '提交给(选择财务)') ?>

                    <?= edit_form_textarea('remark', set_value('remark', $obj->remark), '备注信息') ?>
                </div>

                <div class="col-md-12">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">附加图</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" placeholder="在此处粘贴图片" id="pay_image">
                                <input type="hidden" name="pay_image">
                            </div>
                            <br>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-3"></div>
                            <div class="col-xs-7">
                                <div class="image_contain" id="image"></div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">附加图1</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" placeholder="在此处粘贴图片" id="pay_image_1">
                                <input type="hidden" name="pay_image_1">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-3"></div>
                            <div class="col-xs-7">
                                <div class="image_contain" id="image_1"></div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">附加图2</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" placeholder="在此处粘贴图片" id="pay_image_2">
                                <input type="hidden" name="pay_image_2">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-3"></div>
                            <div class="col-xs-7">
                                <div class="image_contain" id="image_2"></div>
                            </div>
                        </div>
                    </div>

                    <script>
                        (function () {
                            var imgReader = function (item) {
                                var blob = item.getAsFile(),
                                    reader = new FileReader();

                                reader.onload = function (e) {
                                    var img = '<img style="width:100%" src="'+e.target.result+'">';
                                    $("input[name='pay_image']").val(e.target.result);
                                    $('#image').html(img);
                                };

                                reader.readAsDataURL(blob);
                            };
                            var imgReader1 = function (item) {
                                var blob = item.getAsFile(),
                                    reader = new FileReader();

                                reader.onload = function (e) {
                                    var img = '<img style="width:100%" src="'+e.target.result+'">';
                                    $("input[name='pay_image_1']").val(e.target.result);
                                    $('#image_1').html(img);
                                };

                                reader.readAsDataURL(blob);
                            };
                            var imgReader2 = function (item) {
                                var blob = item.getAsFile(),
                                    reader = new FileReader();

                                reader.onload = function (e) {
                                    var img = '<img style="width:100%" src="'+e.target.result+'">';
                                    $("input[name='pay_image_2']").val(e.target.result);
                                    $('#image_2').html(img);
                                };

                                reader.readAsDataURL(blob);
                            };

                            document.getElementById('pay_image').addEventListener('paste', function (e) {
                                var clipboardData = e.clipboardData,
                                    i = 0,
                                    items, item, types;

                                if (clipboardData) {
                                    items = clipboardData.items;

                                    if (!items) {
                                        return;
                                    }

                                    item = items[0];
                                    types = clipboardData.types || [];

                                    for (; i < types.length; i++) {
                                        if (types[i] === 'Files') {
                                            item = items[i];
                                            break;
                                        }
                                    }

                                    if (item && item.kind === 'file' && item.type.match(/^image\//i)) {
                                        imgReader(item);
                                    }
                                }
                            });
                            document.getElementById('pay_image_1').addEventListener('paste', function (e) {
                                var clipboardData = e.clipboardData,
                                    i = 0,
                                    items, item, types;

                                if (clipboardData) {
                                    items = clipboardData.items;

                                    if (!items) {
                                        return;
                                    }

                                    item = items[0];
                                    types = clipboardData.types || [];

                                    for (; i < types.length; i++) {
                                        if (types[i] === 'Files') {
                                            item = items[i];
                                            break;
                                        }
                                    }

                                    if (item && item.kind === 'file' && item.type.match(/^image\//i)) {
                                        imgReader1(item);
                                    }
                                }
                            });
                            document.getElementById('pay_image_2').addEventListener('paste', function (e) {
                                var clipboardData = e.clipboardData,
                                    i = 0,
                                    items, item, types;

                                if (clipboardData) {
                                    items = clipboardData.items;

                                    if (!items) {
                                        return;
                                    }

                                    item = items[0];
                                    types = clipboardData.types || [];

                                    for (; i < types.length; i++) {
                                        if (types[i] === 'Files') {
                                            item = items[i];
                                            break;
                                        }
                                    }

                                    if (item && item.kind === 'file' && item.type.match(/^image\//i)) {
                                        imgReader2(item);
                                    }
                                }
                            });
                        })();
                    </script>

                    <div style="padding-left: 5%;" class="col-md-12">
                        <?= edit_form_uploader('pay_image_3', set_uploader('pay_image_3', $obj->pay_image_3), '', 1) ?>
                        <?= edit_form_uploader('pay_image_4', set_uploader('pay_image_4', $obj->pay_image_4), '', 1) ?>
                        <?= edit_form_uploader('pay_image_5', set_uploader('pay_image_5', $obj->pay_image_5), '', 1) ?>
                    </div>

                </div>
                <?php $this->load->view('partials/submitButtons.tpl') ?>
                <?= form_close() ?>
            </div>
        </div>

        <!-- Begin: life time stats -->
        <div class="portlet box blue ">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-cogs"></i>已合并的测评记录
                </div>
                <div class="tools">
                    <button type="button" class="btn purple" onclick="iBox()">导出选项</button>
                </div>
            </div>
            <script>
                function iBox() {
                    $('#choose-field').toggle(500, 'swing')
                }
            </script>
            <div style="display:none;" class="portlet-body" id="choose-field">
                <form action="" method="post" id="export_form">
                    <div class="well well-sm" style="margin: 10px 0;">
                        <div class="checkbox" style="margin-bottom: 15px;">
                            <b><i>请选择要导出的字段：</i></b>
                            <label>
                                <input id="all" type="checkbox">
                                全选/全不选
                            </label>
                        </div>
                        <div class="checkbox ibox">
                            <label>
                                <input class="fbox" name="field[]" value="id" type="checkbox">id
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="operator_id" type="checkbox">接单人
                            </label>

                            <label>
                                <input class="fbox" name="field[]" value="task_id" type="checkbox">所属任务
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="asin" type="checkbox">任务sain
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="product_image" type="checkbox">任务图片
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="comment_link" type="checkbox">评论连接
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="shop_id" type="checkbox">店铺
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="order_no" type="checkbox">订单编号
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="buyer_order_time" type="checkbox">买手下单时间
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="buyer_pay_time" type="checkbox">买手付款时间
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="true_product_price" type="checkbox">购买时商品价格
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="buyer_pay_total" type="checkbox">买手下单支付费用
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="buyer_pay_coin_type" type="checkbox">买家付款币种
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="payment_type" type="checkbox">打款类型
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="pay_method" type="checkbox">付款方式
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="contact" type="checkbox">收款联系方式
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="pay_account" type="checkbox">收款账户
                            </label>
                            <label>
                                <input class="fbox" checked name="field[]" value="bank" type="checkbox">开户行信息
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="amount" type="checkbox">应付金额
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="coin_type" type="checkbox">应付币种
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="rate_rmb" type="checkbox">对人民币汇率
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image" type="checkbox">凭证
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image_1" type="checkbox">凭证1
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image_2" type="checkbox">凭证2
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="finance_id" type="checkbox">财务处理者
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="status" type="checkbox">状态
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="remark" type="checkbox">备注
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="create_time" type="checkbox">创建时间
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="update_time" type="checkbox">更新时间
                            </label>
                            <input type="hidden" name="file_name" value="middle_operate_<?= $detail->id ?>">
                            <input type="hidden" name="excel_type" value="MiddleOperate">
                        </div>
                        <div class="text-right">

                            <button id="export-xls" type="button" class="text-right btn blue-madison">原版导出</button>
                            <button id="export-xls-python" type="button" class="text-right btn red">快速导出</button>
                        </div>
                        <script>
                            //php
                            $('#export-xls').click(function () {
                                var data = $('#export_form').serialize();
                                if (data.indexOf('field') == -1) {
                                    toastr.error('请选择要导出的字段！', '失败');
                                    return false;
                                } else {
                                    var x = 1;
                                    var y = 1;
                                    $('#process').modal('show');
                                    setInterval(function () {
                                        x += parseFloat(Math.random(0, 1));
                                        var width = x.toFixed(2) + '%';
                                        if (parseInt(x) >= 99) {
                                            x = y / (y + 1) * 100;
                                            y++;
                                        }
                                        $('#show-process').html(width);
                                        $('#show-process').css('width', width)
                                    }, 1000);
                                    $.ajax({
                                        url: '<?=site_url("/common/ExcelExport/excel_export")?>',
                                        data: $('#export_form').serialize(),
                                        method: 'POST',
                                        dataType: 'json',
                                        success: function (output) {
                                            clearInterval();
                                            console.log(output);
                                            // return;
                                            $('#show-process').html('100%');
                                            $('#show-process').css('width', '100%');
                                            $('#process').modal('hide');
                                            toastr.success(output.msg, '成功');
                                            document.location.href = '/' + output.url;
                                        },
                                        fail: function (data) {
                                            toastr.error(data.msg, '失败')
                                        }
                                    });
                                }
                            });

                            //python
                            $('#export-xls-python').click(function () {
                                var data = $('#export_form').serialize();
                                if (data.indexOf('field') == -1) {
                                    toastr.error('请选择要导出的字段！', '失败');
                                    return false;
                                } else {
                                    var x = 1;
                                    var y = 1;
                                    $('#process').modal('show');
                                    setInterval(function () {
                                        x += parseFloat(Math.random(0, 1));
                                        var width = x.toFixed(2) + '%';
                                        if (parseInt(x) >= 99) {
                                            x = y / (y + 1) * 100;
                                            y++;
                                        }
                                        $('#show-process').html(width);
                                        $('#show-process').css('width', width)
                                    }, 1000);
                                    $.ajax({
                                        url: '<?=site_url("/common/ExcelExport/python_export")?>',
                                        data: $('#export_form').serialize(),
                                        method: 'POST',
                                        dataType: 'json',
                                        success: function (output) {
                                            clearInterval();
                                            console.log(output);
                                            // return;
                                            $('#show-process').html('100%');
                                            $('#show-process').css('width', '100%');
                                            $('#process').modal('hide');
                                            if(output.status){
                                                toastr.success(output.msg, '成功');
                                            }else{
                                                toastr.error(output.msg, '失败');
                                            }
                                            document.location.href = '/' + output.url;
                                        },
                                        fail: function (data) {
                                            toastr.error(data.msg, '失败')
                                        }
                                    });
                                }
                            });

                            $('#all').click(function () {
                                if ($(this).prop("checked") == true) {
                                    $(".fbox").prop('checked', true);
                                    $(".fbox").parent('span').addClass('checked');
                                    return;
                                } else {
                                    $(".fbox").prop('checked', false);
                                    $(".fbox").parent('span').removeClass('checked');
                                    return;
                                }
                            });
                        </script>
                    </div>
                </form>
            </div>

            <div class="portlet-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-scrollable">
                            <table class="table table-hover table-bordered table-striped">
                                <tr>
                                    <th class="text-center" width="3%">ID</th>
                                    <th class="text-center" width="5%">记录ID</th>
                                    <th class="text-center" width="5%">任务ID</th>
                                    <th class="text-center" width="5%">商品名称</th>
                                    <th class="text-center" width="5%">店铺</th>
                                    <th class="text-center" width="5%">接单者</th>
                                    <th class="text-center" width="5%">下单单号</th>
                                    <th class="text-center" width="5%">联系方式</th>
                                    <th class="text-center" width="5%">付款账号</th>
                                    <th class="text-center" width="4%">应付金额</th>
                                    <th class="text-center" width="4%">付款类型</th>
                                    <th class="text-center" width="4%">付款方式</th>
                                    <th class="text-center" width="5%">状态</th>
                                    <th class="text-center" width="6%">创建时间</th>
                                    <?php if ($p->read): ?>
                                        <th class="text-center" width="5%">操作</th>
                                    <?php endif; ?>
                                </tr>
                                <tbody>
                                <?php foreach ($list as $v) { ?>
                                    <tr>
                                        <td><?= $v->id ?></td>
                                        <td><?= $v->record_id ?> - <a style="background:#e20000;color:#fff;padding:2px 5px;" href="javascript:ioss_url_modal('<?= site_url('/tasks/taskrecords/ajaxViewDetail/' . $v->record_id) ?>');">查看</a></td>
                                        <td><?= $v->task_id ?> - <a style="background:#00a200;color:#fff;padding:2px 5px;" href="<?=site_url('/tasks/task/view/'.$v->task_id);?>">查看</a></td>
                                        <td><?= $v->product_name ?></td>
                                        <td><?= $allShops[$v->shop_id] ?></td>
                                        <td><?= $allReviewsAdmin[$v->operator_id]; ?></td>
                                        <td><?= $v->order_no ?></td>
                                        <td class="text-center"><?= htmlspecialchars($v->contact) ?></td>
                                        <td class="text-center"><?= htmlspecialchars($v->pay_account) ?></td>
                                        <td class="text-center"><?= number_format($v->amount, 2, '.', '') ?> (<?= IOSS_StaticConfig::getcoinTypeInfo($v->coin_type) ?>)</td>
                                        <td class="text-center"><?= IOSS_StaticConfig::$payTypeArray[$v->payment_type] ?></td>
                                        <td class="text-center"><?= IOSS_StaticConfig::$payMethod[$v->pay_method] ?></td>
                                        <td class="text-center"><?= MTaskRecordItem::getState($v->status); ?></td>
                                        <td><?= date('Y-m-d H:i', $v->create_time) ?></td>
                                        <?php if ($p->read): ?>
                                            <td>
                                                <a href="javascript:ioss_url_modal('<?= site_url('/tasks/taskrecorditem/ajaxViewDetail/' . $v->id) ?>');"
                                                   class="btn btn-sm blue ">
                                                    <i class="fa fa-play"></i> 查看
                                                </a>
                                            </td>
                                        <?php endif; ?>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right">
                        <?= $pagination ?>
                    </div>
                </div>
            </div>
        </div>
        <!-- End: life time stats -->
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        AjaxUploader.uploadTempUrl = "<?=site_url('/common/AjaxUpload/upload') . '/'  ?>";
        AjaxUploader.init();
        $('.img-rounded').zoomify();
    });
</script>
